﻿Public MustInherit Class ChannelEvent
    Inherits MidiEvent

    Public MustOverride Function ToInt32Message() As Integer

    Public Property Channel As Byte

End Class

Public Class NoteOffEvent
    Inherits ChannelEvent

    Public Property Pitch As Byte
    Public Property Velocity As Byte

    Public Overrides Function ToInt32Message() As Integer
        Return &H80 Or Channel Or (Pitch << 8) Or (Velocity << 16)
    End Function

End Class

Public Class NoteOnEvent
    Inherits ChannelEvent

    Public Property Pitch As Byte
    Public Property Velocity As Byte

    Public Overrides Function ToInt32Message() As Integer
        Return &H90 Or Channel Or (Pitch << 8) Or (Velocity << 16)
    End Function

End Class

Public Class NoteAfterTouchEvent
    Inherits ChannelEvent

    Public Property Pitch As Byte
    Public Property Value As Byte

    Public Overrides Function ToInt32Message() As Integer
        Return &HA0 Or Channel Or (Pitch << 8) Or (Value << 16)
    End Function

End Class

Public Class ControlChangeEvent
    Inherits ChannelEvent

    Public Property Control As Byte
    Public Property Value As Byte

    Public Overrides Function ToInt32Message() As Integer
        Return &HB0 Or Channel Or (Control << 8) Or (Value << 16)
    End Function

End Class

Public Class ProgramChangeEvent
    Inherits ChannelEvent

    Public Property Program As Byte

    Public Overrides Function ToInt32Message() As Integer
        Return &HC0 Or Channel Or (Program << 8)
    End Function

End Class

Public Class ChannelAfterTouchEvent
    Inherits ChannelEvent

    Public Property Value As Byte

    Public Overrides Function ToInt32Message() As Integer
        Return &HD0 Or Channel Or (Value << 8)
    End Function

End Class

Public Class PitchBendEvent
    Inherits ChannelEvent

    Public Property Value As Short

    Public Overrides Function ToInt32Message() As Integer
        Dim LSB As Byte = CByte(Value And &H7F)
        Dim MSB As Byte = CByte((Value >> 7) And &H7F)
        Return &HE0 Or Channel Or (LSB << 8) Or (MSB << 16)
    End Function

End Class

